import string, sys, os
from platform import system

Import('platform_name arch')

libs = []

if system() == 'Linux':
    cflags = ['-Wall', '-O2',
                '-fno-exceptions',
                '-Wconversion',
                '-Wpointer-arith',
                '-Wcast-align',
                '-Wno-long-long',
                '-pedantic',
                '-fshort-wchar',
                '-pthread', '-pipe']

elif system() == 'Darwin':
    cflags = ['-Wall', '-O2',
                '-fno-exceptions',
                '-Wconversion',
                '-Wpointer-arith',
                '-Wcast-align',
                '-Wno-long-long',
                '-pedantic',
                '-fshort-wchar',
                '-pthread', '-pipe']

elif system() == 'Windows':
    cflags = ['/DWIN32', '/DXP_WIN', '/nologo', '/MT', '/O2']

elif system() == 'FreeBSD':
    cflags = ['-DOSTYPE="FreeBSD7"',
                '-DOSARCH=FreeBSD',
                '-Wall', '-O2',
                '-fPIC', '-fno-exceptions',
                '-fno-strict-aliasing', '-pipe', '-fshort-wchar',
                '-Wconversion', '-Wpointer-arith',
                '-Wcast-align', '-Wno-long-long',
                '-DNDEBUG', '-DTRIMMED',]

linkflags = []


env = Environment(
    LIBS=libs,
    CFLAGS=cflags,
    TARGET_ARCH=arch)

if system() != 'Windows':
    if arch == 'x86_64':
        # you need to install libc6-dev-amd64 g++-multilib lib64stdc++6
        env.AppendUnique(CFLAGS=['-m64'], LINKFLAGS=['-m64'])
    else:
        env.AppendUnique(CFLAGS=['-m32'], LINKFLAGS=['-m32'])

libchmfox = env.SharedLibrary(
    'libchmfox',
    ['chm_lib.c', 'lzx.c', 'export.c', 'extra.c'])

# install = env.Install('#lib/%s' % platform_name, libchmfox[0])

# env.Alias('binary', install)

xpts = []
Return('xpts')
